/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * V1ConsBusqAvan.java
 *
 * Created on 14-may-2012, 12:39:08
 */
package practtica4;

import BBDD.GestorBBDD;
import DTO.Acontecimiento;
import DTO.Colectivo;
import DTO.Documento;
import DTO.Personaje;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author usuario_local
 */
public class V1ConsBusqAvan extends javax.swing.JFrame {
 
    /** Creates new form V1ConsBusqAvan */
       GestorBBDD gestor=new GestorBBDD();
    public V1ConsBusqAvan() {
      
        initComponents(); 
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        labelQueBuscar = new javax.swing.JLabel();
        comboBuscar = new javax.swing.JComboBox();
        labelId = new javax.swing.JLabel();
        botonId = new javax.swing.JTextField();
        botonAceptar = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        botonnombre = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        botonalias = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        labelQueBuscar.setText("Buscar");

        comboBuscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Personaje", "Acontecimiento", "Colectivo" }));
        comboBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                comboBuscarActionPerformed(evt);
            }
        });

        labelId.setText("id");

        botonAceptar.setText("Aceptar");
        botonAceptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                botonAceptarMouseClicked(evt);
            }
        });

        jLabel1.setText("Nombre");

        jLabel2.setText("Introduzca los datos con los que realizar la búsqueda:");

        jLabel3.setText("Alias");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(77, 77, 77)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel1)
                            .addComponent(labelId)
                            .addComponent(labelQueBuscar)
                            .addComponent(jLabel3))
                        .addGap(84, 84, 84)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(botonId)
                            .addComponent(comboBuscar, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(botonnombre, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botonalias, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(79, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(botonAceptar)
                .addGap(55, 55, 55))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addComponent(jLabel2)
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelQueBuscar)
                    .addComponent(comboBuscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(27, 27, 27)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelId))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(botonnombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(22, 22, 22)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botonalias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGap(48, 48, 48)
                .addComponent(botonAceptar)
                .addContainerGap(35, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void botonAceptarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botonAceptarMouseClicked
        String tipo=comboBuscar.getSelectedItem().toString();
        String id= this.botonId.getText();
        String nombre= this.botonnombre.getText();
        String alias= this.botonalias.getText();
        String buscar= tipo+" "+id+" "+nombre+" "+alias;
        ArrayList<Colectivo> colects = null;
        ArrayList<Acontecimiento> aconts = null;
        ArrayList<Personaje> pers = null;
       
        if(tipo.equals("Colectivo")){
            if(id.equals("")&&nombre.equals(""))  JOptionPane.showMessageDialog(this, "Rellenar id y/o Nombre");
            else try {
                colects=gestor.recuperaColectivoAvanz(id,nombre);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
        if(tipo.equals("Acontecimiento")){
            if(id.equals("")&&nombre.equals(""))  JOptionPane.showMessageDialog(this, "Rellenar id y/o Nombre");
            else try {
                aconts=gestor.recuperaAcontecimientoAvanz(id,nombre);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
        if(tipo.equals("Personaje")){
            if(id.equals("") && nombre.equals("") && alias.equals(""))  
                JOptionPane.showMessageDialog(this, "Rellenar id,Nombre y/o Alias  ");
            else try {
                pers=gestor.recuperaPersonajeAvanz(id,nombre,alias);
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
            } catch (SQLException ex) {
                Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
            }
         }
        ArrayList<Documento> docs = null;
        try {
           docs= gestor.busquedaSimpleD(null,aconts,colects,pers);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(V1ConsBusqAvan.class.getName()).log(Level.SEVERE, null, ex);
        }
        V1BusqSimpleEligeResult v1res= new V1BusqSimpleEligeResult(buscar,aconts,colects,pers,docs);
        v1res.setVisible(true);
        this.dispose();
        
        
    }//GEN-LAST:event_botonAceptarMouseClicked

    private void comboBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBuscarActionPerformed
       
        
    }//GEN-LAST:event_comboBuscarActionPerformed

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botonAceptar;
    private javax.swing.JTextField botonId;
    private javax.swing.JTextField botonalias;
    private javax.swing.JTextField botonnombre;
    private javax.swing.JComboBox comboBuscar;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel labelId;
    private javax.swing.JLabel labelQueBuscar;
    // End of variables declaration//GEN-END:variables
}
